"use strict";
const common_vendor = require("../../../common/vendor.js");
const api_complaint_index = require("../../../api/complaint/index.js");
const utils_tools = require("../../../utils/tools.js");
const config_app = require("../../../config/app.js");
const stores_userInfo = require("../../../stores/userInfo.js");
if (!Array) {
  const _easycom_up_tabs2 = common_vendor.resolveComponent("up-tabs");
  const _easycom_up_album2 = common_vendor.resolveComponent("up-album");
  const _easycom_up_empty2 = common_vendor.resolveComponent("up-empty");
  const _easycom_up_gap2 = common_vendor.resolveComponent("up-gap");
  const _easycom_up_toast2 = common_vendor.resolveComponent("up-toast");
  const _easycom_up_radio2 = common_vendor.resolveComponent("up-radio");
  const _easycom_up_radio_group2 = common_vendor.resolveComponent("up-radio-group");
  const _easycom_up_popup2 = common_vendor.resolveComponent("up-popup");
  (_easycom_up_tabs2 + _easycom_up_album2 + _easycom_up_empty2 + _easycom_up_gap2 + _easycom_up_toast2 + _easycom_up_radio2 + _easycom_up_radio_group2 + _easycom_up_popup2)();
}
const _easycom_up_tabs = () => "../../../node-modules/uview-plus/components/u-tabs/u-tabs.js";
const _easycom_up_album = () => "../../../node-modules/uview-plus/components/u-album/u-album.js";
const _easycom_up_empty = () => "../../../node-modules/uview-plus/components/u-empty/u-empty.js";
const _easycom_up_gap = () => "../../../node-modules/uview-plus/components/u-gap/u-gap.js";
const _easycom_up_toast = () => "../../../node-modules/uview-plus/components/u-toast/u-toast.js";
const _easycom_up_radio = () => "../../../node-modules/uview-plus/components/u-radio/u-radio.js";
const _easycom_up_radio_group = () => "../../../node-modules/uview-plus/components/u-radio-group/u-radio-group.js";
const _easycom_up_popup = () => "../../../node-modules/uview-plus/components/u-popup/u-popup.js";
if (!Math) {
  (_easycom_up_tabs + _easycom_up_album + _easycom_up_empty + _easycom_up_gap + _easycom_up_toast + _easycom_up_radio + _easycom_up_radio_group + _easycom_up_popup)();
}
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "detail",
  setup(__props) {
    stores_userInfo.useUserInfoStore();
    const uToastRef = common_vendor.ref(null);
    const data = common_vendor.reactive({
      queryParam: {
        pageNum: 1,
        pageSize: 10,
        communityId: void 0,
        effectiveStatus: "",
        type: void 0,
        yearMonth: void 0
      },
      countQuery: {
        communityId: void 0,
        type: void 0,
        yearMonth: void 0
      },
      tabs: [{ name: "全部" }, { name: "有效投诉" }, { name: "无效投诉" }],
      list: [],
      total: 0,
      form: {
        id: void 0,
        effectiveStatus: null
      }
    });
    const { queryParam, countQuery, tabs, list, total, form } = common_vendor.toRefs(data);
    const current = common_vendor.ref(0);
    const showPopup = common_vendor.ref(false);
    const onTypeItem = (item) => {
      current.value = item.index;
      switch (item.index) {
        case 0:
          queryParam.value.effectiveStatus = "";
          break;
        case 1:
          queryParam.value.effectiveStatus = 1;
          break;
        case 2:
          queryParam.value.effectiveStatus = 0;
          break;
      }
      list.value = [];
      total.value = 0;
      queryParam.value.pageNum = 1;
      getComplaintList();
    };
    const getComplaintList = () => {
      api_complaint_index.listComplaint(queryParam.value).then((res) => {
        const { data: data2 } = res;
        data2.records = data2.records ?? [];
        data2.records = arrProcess(data2.records);
        list.value = [...list.value, ...data2.records];
        total.value = data2.total;
      }).catch((err) => {
        uToastRef.value.show({
          type: "error",
          message: err
        });
      });
    };
    const getComplaintCount = () => {
      api_complaint_index.complaintStatCount(countQuery.value).then((res) => {
        const { data: data2 } = res;
        tabs.value[0].name = `全部（${data2.sumCount}）`;
        tabs.value[1].name = `有效投诉（${data2.invalidCount}）`;
        tabs.value[2].name = `无效投诉（${data2.effectiveCount}）`;
      }).catch((err) => {
        uToastRef.value.show({
          type: "error",
          message: err
        });
      });
    };
    const arrProcess = (arr) => {
      if (arr.length) {
        arr = arr.map((item) => {
          let badgeNumberArr = [];
          let policeNameArr = [];
          if (item.badgeNumber && item.badgeNumber.includes("、")) {
            badgeNumberArr = item.badgeNumber.split("、");
          }
          if (item.policeName && item.policeName.includes("、")) {
            policeNameArr = item.policeName.split("、");
          }
          item.users = [];
          if (badgeNumberArr.length && policeNameArr.length) {
            policeNameArr.forEach((it, index) => {
              item.users.push(
                item.communityName + " " + it + " " + badgeNumberArr[index]
              );
            });
          } else {
            item.users.push(
              item.communityName + " " + item.policeName + " " + item.badgeNumber
            );
          }
          if (item.imgUrl) {
            item.imgUrl = item.imgUrl.split(",");
            if (item.imgUrl.length) {
              item.imgUrl = item.imgUrl.map((img) => {
                img = config_app.imgPrefix + img;
                return img;
              });
            }
          }
          return item;
        });
      }
      return arr;
    };
    const showStatusPopup = (row) => {
      form.value.id = row.id;
      form.value.effectiveStatus = row.effectiveStatus;
      showPopup.value = true;
    };
    const onsubmit = () => {
      api_complaint_index.updateComplaintStatus(form.value).then((res) => {
        uToastRef.value.show({
          type: "success",
          message: "状态设置成功"
        });
        showPopup.value = false;
        list.value = [];
        total.value = 0;
        getComplaintList();
        getComplaintCount();
      }).catch((err) => {
        uToastRef.value.show({
          type: "error",
          message: err
        });
      });
    };
    common_vendor.onLoad((options) => {
      if (options && options.detailInfo) {
        let detailInfo = JSON.parse(options.detailInfo);
        queryParam.value.communityId = detailInfo.communityId;
        queryParam.value.type = options.type;
        queryParam.value.yearMonth = options.yearMonth;
        countQuery.value.communityId = detailInfo.communityId;
        countQuery.value.type = options.type;
        countQuery.value.yearMonth = options.yearMonth;
        getComplaintList();
        getComplaintCount();
      }
    });
    common_vendor.onReachBottom(() => {
      let allTotal = queryParam.value.pageNum * queryParam.value.pageSize;
      if (allTotal < total.value) {
        queryParam.value.pageNum++;
        getComplaintList();
      } else {
        uToastRef.value.show({
          type: "info",
          message: "暂无更多数据"
        });
        return;
      }
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.o(onTypeItem),
        b: common_vendor.p({
          list: common_vendor.unref(tabs),
          lineColor: "#0A8CFE",
          lineWidth: "70rpx",
          activeStyle: {
            color: "#0A8CFE",
            fontSize: "29rpx"
          },
          inactiveStyle: {
            color: "#000",
            fontSize: "29rpx"
          }
        }),
        c: common_vendor.unref(list).length
      }, common_vendor.unref(list).length ? {
        d: common_vendor.f(common_vendor.unref(list), (item, index, i0) => {
          return common_vendor.e({
            a: common_vendor.t(item.content),
            b: common_vendor.t(item.users.join("、")),
            c: item.imgUrl && item.imgUrl.length
          }, item.imgUrl && item.imgUrl.length ? {
            d: "fd5d5dc2-1-" + i0,
            e: common_vendor.p({
              urls: item.imgUrl,
              space: "20rpx",
              singleSize: "155rpx",
              multipleSize: "155rpx",
              autoWrap: true,
              maxCount: 3,
              unit: "rpx"
            })
          } : {}, {
            f: common_vendor.t(item.complaintUserName),
            g: common_vendor.t(common_vendor.unref(utils_tools.EncryptTel)(item.phonenumber)),
            h: common_vendor.t(item.createTime ? common_vendor.unref(common_vendor.dayjs)(item.createTime).format("YYYY-MM-DD hh:mm:ss") : ""),
            i: item.effectiveStatus === 2
          }, item.effectiveStatus === 2 ? {
            j: common_vendor.o(($event) => showStatusPopup(item), index)
          } : common_vendor.e({
            k: item.effectiveStatus == 1
          }, item.effectiveStatus == 1 ? {} : {}), {
            l: index
          });
        })
      } : {
        e: common_vendor.p({
          mode: "data",
          text: "暂无记录",
          icon: "http://cdn.uviewui.com/uview/empty/data.png"
        })
      }, {
        f: common_vendor.p({
          height: "10"
        }),
        g: common_vendor.sr(uToastRef, "fd5d5dc2-4", {
          "k": "uToastRef"
        }),
        h: common_vendor.p({
          activeColor: "#0189FE",
          name: 1,
          label: "有效"
        }),
        i: common_vendor.p({
          activeColor: "#0189FE",
          name: 0,
          label: "无效"
        }),
        j: common_vendor.o(($event) => common_vendor.unref(form).effectiveStatus = $event),
        k: common_vendor.p({
          placement: "row",
          labelColor: "#000000",
          modelValue: common_vendor.unref(form).effectiveStatus
        }),
        l: common_vendor.o(onsubmit),
        m: common_vendor.o(($event) => showPopup.value = false),
        n: common_vendor.p({
          show: common_vendor.unref(showPopup),
          round: 8,
          mode: "center",
          closeOnClickOverlay: true
        })
      });
    };
  }
});
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-fd5d5dc2"]]);
wx.createPage(MiniProgramPage);
